#include "GraphicEngine.h"
#include <iostream>
#include "windows.h"
#include "typedef.h"

using namespace std;

GraphicEngine::GraphicEngine(void):GraphicEngine_base()
{
	renderWater = false;
	renderEffects = false;
	ShaderFX.renderBloom = false;
	ShaderFX.renderColor = false;

}

GraphicEngine::~GraphicEngine(void)
{
	delete waternode;
}

void GraphicEngine::FlushAll(void)
{
  // Pulisco tutti i nodi
  smgr->clear(); // Pulisco tutto
  smgr->getGUIEnvironment()->clear();

  // Pulisco la Mesh Cache
  scene::IMeshCache* cache = smgr->getMeshCache();
  scene::IMesh* myMesh;
  int temp = cache->getMeshCount();
  for (int i=temp; i>=0; i--)
  {
	  myMesh = cache->getMeshByIndex(temp);
	  cache->removeMesh(myMesh);
  }
  cache->grab();
  cache->drop();
  
  // Pulisco la texture cache
  if (driver->getTextureCount() != 0)
	  driver->removeAllTextures();
}

void GraphicEngine::RestartEngine(void)
{
	video::E_DRIVER_TYPE driverType;
	driverType = driver->getDriverType();
	myRecv = device->getEventReceiver();
	// Closing, Flushing, Restarting
	FlushAll();
	device->closeDevice();
	device->run(); // Confirm Closing
	device->grab(); // Grabbing Pointers
	device->drop();
	InitEngine(); // Reinitializing Engine
	if (myRecv != NULL)
		device->setEventReceiver(myRecv);
	// Run the new device
	device->run();
}

void GraphicEngine::LoadBuiltInResources(void)
{
	ObjectDrawings();
	EnvironmentalDrawings();
}

void GraphicEngine::InitEngine(void)
{
	// INITIALIZING CAMERA CONTROLS
	keyMap[0].Action = EKA_MOVE_FORWARD;
	keyMap[0].KeyCode = KEY_KEY_W;

	keyMap[1].Action = EKA_MOVE_BACKWARD;
	keyMap[1].KeyCode = KEY_KEY_S;

	keyMap[2].Action = EKA_STRAFE_LEFT;
	keyMap[2].KeyCode = KEY_KEY_A;

	keyMap[3].Action = EKA_STRAFE_RIGHT;
	keyMap[3].KeyCode = KEY_KEY_D;

	// DEFAULT CREAZIONE DEVICE
	device = createDevice(driverType, core::dimension2d<s32>((int)HRES,(int)VRES), COLORBIT, FULLSCREEN, STENCIL, VSINC);
	if (device==NULL) exit(-1);
	
	// DEFAULT INIZIALIZZAZIONE AMBIENTE
	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
	env = device->getGUIEnvironment();
	cmgr = smgr->getSceneCollisionManager();

	// SETTAGGIO DRIVER DI DISEGNO
	driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, ETCF_BIT);
	driver->setTextureCreationFlag(video::ETCF_OPTIMIZED_FOR_QUALITY, ETCF_QUALITY);
	driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, ETCF_MIPMAP);

	// CAMERA (Input Disabled by default)
	camera = smgr->addCameraSceneNodeFPS(0,100.0f,1.0f,-1,keyMap,4); 
	camera->setInputReceiverEnabled(false);
	camera->setName(CAMERA);

	// DISABILITO CURSORE MOUSE
	device->getCursorControl()->setVisible(false);

	// SENSIBILAB LOGO
	/*env->addImage(driver->getTexture("../Media/Logos/Logo.tga"),
			core::position2d<s32>(10,10));
		core::stringw WinTitle;*/
}

void GraphicEngine::ConfigEngine(char *driverSelected,int hres,int vres, char *mode, char *bitcolor, char *vsinch)
{
	//DEFAULT DRIVER VIDEO INITIALIZATION
	std::cout<<"Driver video: ";
	if (strcmp(driverSelected,"OPENGL")==0){
		 driverType=video::EDT_OPENGL;
		 std::cout<<driverSelected<<endl;}	
	else if (strcmp(driverSelected,"DIRECTX8")==0){
		driverType=video::EDT_DIRECT3D8;
		std::cout<<driverSelected<<endl;}
	else if (strcmp(driverSelected,"DIRECTX9")==0){
		driverType=video::EDT_DIRECT3D9;
		std::cout<<driverSelected<<endl;}
	else
	{
		std::cout<<"Driver video errato!"<<endl;;
		MessageBox(0,L"Ops. The video drive you have selected is wrong. Select from: OPENGL, DIRECTX8, DIRECTX9",L"ERROR",0);
		exit(-1);
	}
	HRES = hres;
	VRES = vres;
	if (strcmp(mode,"TRUE")==NULL)
		FULLSCREEN = true;
	else
		FULLSCREEN = false;
	
	if (strcmp(vsinch,"TRUE")==NULL)
		VSINC=true;
	else
		VSINC=false;
	COLORBIT=atoi(bitcolor);
}

void GraphicEngine::AnimatedSkydome(char *SkyTexPath)
{
	// SKYBOX
	skydome = smgr->addSkyDomeSceneNode  (driver->getTexture(SkyTexPath),30,30,1,2,NULL);
	skydome->addAnimator(smgr->createRotationAnimator(core::vector3df(0, -0.005f, 0)));
	skydome->setName(SKY);
}

void GraphicEngine::RealisticWaterNode(f32 tileSize, u32 tileCount, core::dimension2di RenderTargetSize)
{
	//WATER
	waternode = new CReflectedWater("ReflectiveWater", device, smgr, -1, tileSize, tileCount, RenderTargetSize);
	waternode->m_WaveDisplacement /= 5.0f;
	waternode->m_WaveHeight *= 0.2f;
	waternode->m_WaveSpeed *= 0.3f;
	waternode->m_RefractionFactor = 1.0f;
	waternode->m_AddedColor      = video::SColor(255, 1, 1, 20);
	waternode->m_MultiColor      = video::SColor(255, 150, 200, 240);
	waternode->m_WaveRepetition   = 20.0f;
	waternode->m_waternode->setMaterialFlag(video::EMF_FOG_ENABLE,true);
	waternode->m_waternode->setVisible(false);
}

void GraphicEngine::EnvironmentalDrawings(void)
{
	// EFFECTS
	CreateGlow(camera,smgr,50);
	CreateDreamFilter(camera,smgr,0.02f,50);
	// FOG
	driver->setFog(video::SColor(150,200,200,255),false, 500, 10000, 0.00005f,true,false);
	// SKYDOME
	AnimatedSkydome(SKYDOME_PATH);
	// REALISTIC REFLECTIVE WATER
	RealisticWaterNode(100, 50, core::dimension2di(512,512));
	// POST-PROCESSING SHADERS
	video::E_DRIVER_TYPE driverType;
	driverType = driver->getDriverType();
	if (driverType == video::EDT_OPENGL)
	{
		// Bloom
		ShaderFX.Bloom = new IPostProcessBloom(smgr->getRootSceneNode(), smgr, 666);
		ShaderFX.BloomSetup.sampleDist=(float)0.008;
		ShaderFX.BloomSetup.strength=3;
		ShaderFX.BloomSetup.multiplier=2;
		// Color
		ShaderFX.Color = new IPostProcessColor(smgr->getRootSceneNode(), smgr, 666);
		ShaderFX.ColorSetup.saturation=4;
		ShaderFX.ColorSetup.coloringStrength=5;
		ShaderFX.ColorSetup.col=video::SColorf(0,255,128,0);
	}
}

void GraphicEngine::ObjectDrawings(void)
{
	scene::IAnimatedMesh* myMesh;
	scene::ISceneNode*	mySceneNode;
	scene::ITextSceneNode* myTxtNode;
    scene::IBillboardSceneNode* myBillNode;
	scene::IParticleSystemSceneNode* myParticleNode;
	
	//LOAD FROM PK3/ZIP FILE
	//if (!(device->getFileSystem()->addZipFileArchive("../media/Media.pk3",false,true))) return;

	// ANIMATORS
	anim =smgr->createRotationAnimator(core::vector3df(0,5.0f,0));
	
	// AENIMA - TEXT NODE SCRIPTING
	myTxtNode = smgr->addTextSceneNode(env->getFont("../Media/Fonts/quantumflat.bmp"), L"AEnima",
		video::SColor(0,255,255,255),camera,core::vector3df(0,0,1));
	myTxtNode->setVisible(false);
	// ---------------------------

	// BILLBOARD NODE - CENTER
	myBillNode = smgr->addBillboardSceneNode(camera,core::dimension2d<f32>(20, 20),
		camera->getTarget() + core::vector3df(0.0f, 0.0f, -20.0f),-1);
	myBillNode->setMaterialTexture(0,driver->getTexture("../Media/Particles/portal6.bmp"));
	myBillNode->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
	myBillNode->setMaterialFlag(video::EMF_LIGHTING, false);
	myBillNode->setVisible(false);
	myBillNode->setName(CENTER);
		
	// CUE - MESH IMPORT (SCENE NODE) SCRIPTING
	myMesh = smgr->getMesh("../Media/Mesh/Cue.3ds");
	smgr->getMeshManipulator()->makePlanarTextureMapping(myMesh->getMesh(0), 0.02f);
	mySceneNode = smgr->addAnimatedMeshSceneNode(myMesh);
	mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,255,255,255);
	mySceneNode->setPosition(camera->getTarget());
	mySceneNode->setScale(core::vector3df(7.0f, 7.0f, 7.0f));
	mySceneNode->setRotation(core::vector3df(0.0f, 180.0f, 180.0f));
	mySceneNode->setMaterialFlag(video::EMF_FOG_ENABLE,true);
	//mySceneNode->setMaterialFlag(video::EMF_LIGHTING, false);
	mySceneNode->setMaterialFlag(video::EMF_ANISOTROPIC_FILTER , true);
	//mySceneNode->setMaterialType(video::EMT_PARALLAX_MAP_TRANSPARENT_ADD_COLOR);
	mySceneNode->setVisible(false);
	mySceneNode->setName(CUE);
	mySceneNode = 0;
	myMesh->drop();
	// ----------------------------

	// FEEDBACK LEFT - STANDARD CUBE SCENE NODE
	mySceneNode = smgr->addCubeSceneNode(10,0,-1,core::vector3df(0,0,0),core::vector3df(0,0,0),core::vector3df(0,0,0));
	mySceneNode->setPosition(camera->getTarget() + core::vector3df(-90.0f, 0.0f, 0.0f));
	mySceneNode->setScale(core::vector3df(1.0f, 0.1f, 1.0f));
	//mySceneNode->setMaterialTexture(0, driver->getTexture("plasma3.jpg"));
	mySceneNode->setMaterialFlag(video::EMF_FOG_ENABLE,true);
	//mySceneNode->setMaterialFlag(video::EMF_LIGHTING, false);
	mySceneNode->setMaterialFlag(video::EMF_ANISOTROPIC_FILTER , true);
	//mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,150,150,255);
	mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,255,255,0);
	mySceneNode->setVisible(false);
	mySceneNode->setName(FB_LEFT);
	myParticleNode = ParticleSystem(mySceneNode,camera->getTarget() + core::vector3df(-65.0f,0.0f,-40.0f),core::vector3df(0.1f,0.0f,0.0f),10,500,video::SColor(0,120,150,0),video::SColor(0,255,255,0),0);
	myParticleNode->setName(FB_LEFT_PAR);
	myParticleNode->setVisible(false);
	mySceneNode = 0;
	
	// FEEDBACK RIGHT - STANDARD CUBE SCENE NODE
	mySceneNode = smgr->addCubeSceneNode(10,0,-1,core::vector3df(0,0,0),core::vector3df(0,0,0),core::vector3df(0,0,0));
	mySceneNode->setPosition(camera->getTarget() + core::vector3df(90.0f, 0.0f, 0.0f));
	mySceneNode->setScale(core::vector3df(1.0f, 0.1f, 1.0f));
	//mySceneNode->setMaterialTexture(0, driver->getTexture("waveNM.png"));
	//mySceneNode->setMaterialTexture(0, driver->getTexture("plasma3.jpg"));
	mySceneNode->setMaterialFlag(video::EMF_FOG_ENABLE,true);
	//mySceneNode->setMaterialFlag(video::EMF_LIGHTING, false);
	mySceneNode->setMaterialFlag(video::EMF_ANISOTROPIC_FILTER , true);
	//mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,150,150,255);
	mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,255,255,0);
	mySceneNode->setVisible(false);
	mySceneNode->setName(FB_RIGHT);
	myParticleNode = ParticleSystem(mySceneNode,camera->getTarget()+core::vector3df(+65.0f,0.0f,-40.0f),core::vector3df(-0.1f,0.0f,0.0f),10,500,video::SColor(0,120,150,0),video::SColor(0,255,255,0),0);
	myParticleNode->setName(FB_RIGHT_PAR);
	myParticleNode->setVisible(false);
	mySceneNode = 0;

	// FEEDBACK UP - STANDARD CUBE SCENE NODE
	mySceneNode = smgr->addCubeSceneNode(10,0,-1,core::vector3df(0,0,0),core::vector3df(0,0,0),core::vector3df(0,0,0));
	mySceneNode->setPosition(camera->getTarget() + core::vector3df(0.0f, 65.0f, 0.0f));
	mySceneNode->setScale(core::vector3df(0.1f, 1.0f, 1.0f));
	//mySceneNode->setMaterialTexture(0, driver->getTexture("waveNM.png"));
	//mySceneNode->setMaterialTexture(0, driver->getTexture("plasma3.jpg"));
	mySceneNode->setMaterialFlag(video::EMF_FOG_ENABLE,true);
	//mySceneNode->setMaterialFlag(video::EMF_LIGHTING, false);
	mySceneNode->setMaterialFlag(video::EMF_ANISOTROPIC_FILTER , true);
	//mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,150,150,255);
	mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,255,255,0);
	mySceneNode->setVisible(false);
	mySceneNode->setName(FB_UP);
	myParticleNode = ParticleSystem(mySceneNode,camera->getTarget()+core::vector3df(0.0f,50.0f,-40.0f),core::vector3df(0.0f,-0.1f,0.0f),10,500,video::SColor(0,120,150,0),video::SColor(0,255,255,0),1);
	myParticleNode->setName(FB_UP_PAR);
	myParticleNode->setVisible(false);
	mySceneNode = 0;

	// FEEDBACK DOWN - STANDARD CUBE SCENE NODE
	mySceneNode = smgr->addCubeSceneNode(10,0,-1,core::vector3df(0,0,0),core::vector3df(0,0,0),core::vector3df(0,0,0));
	mySceneNode->setPosition(camera->getTarget() + core::vector3df(0.0f, -65.0f, 0.0f));
	mySceneNode->setScale(core::vector3df(0.1f, 1.0f, 1.0f));
	//mySceneNode->setMaterialTexture(0, driver->getTexture("waveNM.png"));
	//mySceneNode->setMaterialTexture(0, driver->getTexture("plasma3.jpg"));
	mySceneNode->setMaterialFlag(video::EMF_FOG_ENABLE,true);
	//mySceneNode->setMaterialFlag(video::EMF_LIGHTING, false);
	mySceneNode->setMaterialFlag(video::EMF_ANISOTROPIC_FILTER , true);
	//mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,150,150,255);
	mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,255,255,0);
	mySceneNode->setVisible(false);
	mySceneNode->setName(FB_DOWN);
	myParticleNode = ParticleSystem(mySceneNode,camera->getTarget()+core::vector3df(0.0f,-50.0f,-40.0f),core::vector3df(0.0f,0.1f,0.0f),10,500,video::SColor(0,120,150,0),video::SColor(0,255,255,0),0);
	myParticleNode->setName(FB_DOWN_PAR);
	myParticleNode->setVisible(false);
	mySceneNode = 0;
	
	// FEEDBACK - STANDARD CUBE SCENE NODE X MI
	mySceneNode = smgr->addSphereSceneNode (30,32,0,-1,camera->getTarget(),core::vector3df(0,0,0),core::vector3df(1,1,1));
	mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,150,150,255);
	mySceneNode->setVisible(false);
	mySceneNode->setName(BIG_BALL);
	
	// BALL FOR PROTOCOL ACTIVITY
	mySceneNode = smgr->addCubeSceneNode(10,0,-1,camera->getTarget()+core::vector3df(-91.0f, 67.0f, 0.0f),core::vector3df(0,0,0),core::vector3df(1,1,0));
	mySceneNode->setMaterialTexture(0,driver->getTexture("../Media/General Image/on.png"));
	mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,255,255,255);
	mySceneNode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
	mySceneNode->setVisible(false);
	mySceneNode->setName(STATUS_ON);

	mySceneNode = smgr->addCubeSceneNode(10,0,-1,camera->getTarget()+core::vector3df(-91.0f, 67.0f, 0.0f),core::vector3df(0,0,0),core::vector3df(1,1,0));
	mySceneNode->setMaterialTexture(0,driver->getTexture("../Media/General Image/off.png"));
	mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,255,255,255);
	mySceneNode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
	mySceneNode->setVisible(true);
	mySceneNode->setName(STATUS_OFF);
	
	//OBJECT FOR FADE
	fader = device->getGUIEnvironment()->addInOutFader();
   
	//OBJECT FOR MOTOR IMAGERY
	mySceneNode = smgr->addCubeSceneNode(50.0f,0,-1,core::vector3df(0,0,0),
	core::vector3df(0,0,0), core::vector3df(1.0f, 1.0f, 1.0f));
	mySceneNode->setMaterialTexture(0, driver->getTexture("../Media/Cue_Switch/left.png"));
	mySceneNode->setPosition(camera->getTarget() + core::vector3df(0.0f, 0.0f, 0.0f));
	mySceneNode->setScale(core::vector3df(0.5f,0.5f,0.0f));
	mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,255,255,255);
	mySceneNode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
	mySceneNode->setVisible(false);
	mySceneNode->setName(MI_LEFT);

	//OBJECT FOR MOTOR IMAGERY
	mySceneNode = smgr->addCubeSceneNode(50.0f,0,-1,core::vector3df(0,0,0),
	core::vector3df(0,0,0), core::vector3df(1.0f, 1.0f, 1.0f));
	mySceneNode->setMaterialTexture(0, driver->getTexture("../Media/Cue_Switch/right.png"));
	mySceneNode->setPosition(camera->getTarget() + core::vector3df(0.0f, 0.0f, 0.0f));
	mySceneNode->setScale(core::vector3df(0.5f,0.5f,0.0f));
	mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,255,255,255);
	mySceneNode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
	mySceneNode->setVisible(false);
	mySceneNode->setName(MI_RIGHT);

	//OBJECT FOR MOTOR IMAGERY
	mySceneNode = smgr->addCubeSceneNode(50.0f,0,-1,core::vector3df(0,0,0),
	core::vector3df(0,0,0), core::vector3df(1.0f, 1.0f, 1.0f));
	mySceneNode->setMaterialTexture(0, driver->getTexture("../Media/Cue_Switch/up.png"));
	mySceneNode->setPosition(camera->getTarget() + core::vector3df(0.0f, 0.0f, 0.0f));
	mySceneNode->setScale(core::vector3df(0.5f,0.5f,0.0f));
	mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,255,255,255);
	mySceneNode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
	mySceneNode->setVisible(false);
	mySceneNode->setName(MI_UP);

	//OBJECT FOR MOTOR IMAGERY
	mySceneNode = smgr->addCubeSceneNode(50.0f,0,-1,core::vector3df(0,0,0),
	core::vector3df(0,0,0), core::vector3df(1.0f, 1.0f, 1.0f));
	mySceneNode->setMaterialTexture(0, driver->getTexture("../Media/Cue_Switch/down.png"));
	mySceneNode->setPosition(camera->getTarget() + core::vector3df(0.0f, 0.0f, 0.0f));
	mySceneNode->setScale(core::vector3df(0.5f,0.5f,0.0f));
	mySceneNode->getMaterial(0).EmissiveColor = video::SColor(0,255,255,255);
	mySceneNode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
	mySceneNode->setVisible(false);
	mySceneNode->setName(MI_DOWN);
}

void GraphicEngine::ExEngine()
{
	//driver->beginScene(true, true, 0);

	// Water RTE
	if (renderWater)
		waternode->updateRendertarget(smgr);
	// TGM Shader PostProcessing (Render The entire scene into the renderTarget)
	if (ShaderFX.renderBloom)
	{
		driver->setRenderTarget(ShaderFX.Bloom->rt0, true, true, video::SColor(0,0,0,0));
	}
	if (ShaderFX.renderColor)
	{
		driver->setRenderTarget(ShaderFX.Color->rt0, true, true, video::SColor(0,0,0,0));
	}
	// Special RTE
	if (renderEffects)
	{
		RenderGlow(smgr,10,10,10,10,10);
		RenderDreamFilter(smgr,10,10,10,10);
	}

	
	smgr->drawAll();
	env->drawAll();
	//device->yield();

	// TGM Shader PostProcessing (set The Rendertarget back to the main view and render effect)
	if (ShaderFX.renderBloom)
	{
		driver->setRenderTarget(0);            
		ShaderFX.Bloom->render();                                                 
	}
	if (ShaderFX.renderColor)
	{
		driver->setRenderTarget(0);            
		ShaderFX.Color->render();                                                 
	}
	//driver->endScene();
}

scene::IParticleSystemSceneNode* GraphicEngine::ParticleSystem(scene::ISceneNode* ParentNode,core::vector3df Position, core::vector3df EmiDirection, u32 nMin, u32 nMax, video::SColor MinStartColor, video::SColor MaxStartColor, s32 Angle)
{
	// add particle system
	scene::IParticleSystemSceneNode* myParticleNode;

	myParticleNode = smgr->addParticleSystemSceneNode(false, ParentNode);
	//myParticleNode->setParticlessetParticleSize(core::dimension2d<f32>(8.0f, 8.0f));
	myParticleNode->setPosition(Position);

	// create and set emitter
	scene::IParticleEmitter* em = myParticleNode->createBoxEmitter(
		core::aabbox3d<f32>(-3,0,-3,3,1,3), 
		EmiDirection,
		nMin,nMax, 
		MinStartColor, MaxStartColor,
		500,500,Angle);
	myParticleNode->setEmitter(em);
	em->drop();

	// create and set affector
	scene::IParticleAffector* paf = myParticleNode->createFadeOutParticleAffector();
	myParticleNode->addAffector(paf);
	paf->drop();

	// adjust some material settings
	myParticleNode->setMaterialFlag(video::EMF_LIGHTING, false);
	myParticleNode->setMaterialTexture(0, driver->getTexture("../Media/Particles/portal4.bmp"));
	//myParticleNode->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
	myParticleNode->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);

	return myParticleNode;
}

void GraphicEngine::DrawCentered2DImage(video::ITexture *CenterTexture)
{
	s32 BGPosX = (driver->getScreenSize().Width - CenterTexture->getSize().Width)/2;
	s32 BGPosY = (driver->getScreenSize().Height - CenterTexture->getSize().Height)/2;

	driver->draw2DImage(CenterTexture,core::position2d<s32>(BGPosX,BGPosY));
}

void GraphicEngine::SplashScreen(void)
{
#define sumChar 54222 //Control number for splash image
	FILE *img;
	int cont;
	char c;
	cont=0;
	//SplashScreen control
	img = fopen("../Media/Logos/SPLASH.tga","r");
	if (img==NULL)
	{
		MessageBox(0,L"Ops. SplashScreen.jpg not found, please reload the original image.",L"ERROR",0);
		exit(-1);
	}
	while (!feof(img))
	{
		fscanf(img,"%c",&c);
		cont=cont+c;
	}
	if (cont!=sumChar)
	{
		MessageBox(0,L"Ops. your SplashScreen.jpg is not the original,\nplease reload the original image",L"ERROR",0);
		exit(-1);
	}

	driver->beginScene(true,true,0);
	DrawCentered2DImage(driver->getTexture("../Media/Logos/SPLASH.tga"));
    driver->endScene();
	Sleep(2500); //Logo visualization time
    //} 
}

void GraphicEngine::GLShaderFX(bool BloomON,bool ColorON)
{
	video::E_DRIVER_TYPE driverType;
	driverType = driver->getDriverType();
	if (driverType == video::EDT_OPENGL)
	{
		ShaderFX.renderBloom = BloomON;
		ShaderFX.Bloom->initiate(driver->getScreenSize().Width,driver->getScreenSize().Height,ShaderFX.BloomSetup,smgr);

		ShaderFX.renderColor = ColorON;
		ShaderFX.Color->initiate(driver->getScreenSize().Width,driver->getScreenSize().Height,ShaderFX.ColorSetup,smgr);
	}
}